    package cn.tedu.micro.demo.client.exchange;

    import cn.tedu.micro.demo.client.RabbitChannelManager;
    import com.rabbitmq.client.BuiltinExchangeType;
    import com.rabbitmq.client.Channel;
    import lombok.extern.slf4j.Slf4j;
    import org.junit.jupiter.api.Test;

    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;

    /**
     * 测试头交换机
     */
    @Slf4j
    public class HeaderExchange {
        //按照笔记的结构 声明queue1 2 3 header_ex交换机 声明绑定
        @Test
        public void headerBindQueues() throws IOException {
            //1.获取连接
            Channel channel = RabbitChannelManager.newChannel();
            //2.队列queue1 2 3 重复使用 重置清空
            channel.queueDelete("queue1");
            channel.queueDelete("queue2");
            channel.queueDelete("queue3");
            //3.声明3个队列
            channel.queueDeclare("queue1", false, false, false, null);
            channel.queueDeclare("queue2", false, false, false, null);
            //4.声明交换机,只需要2个参数 一个是交换机名字 ,一个是交换机类型
            channel.exchangeDeclare("header_ex", BuiltinExchangeType.HEADERS);
            //5.绑定队列 和 交换机 使用路由key值
            /*
                {
                    "x-match":"any",
                    "name":"王翠花",
                    "age":18
                }
             */
            Map<String,Object> headers1=new HashMap<>();
            headers1.put("x-match","any");
            headers1.put("name","王翠花");
            headers1.put("age",18);
            channel.queueBind("queue1","header_ex","",headers1);
            /*
                {
                    "x-match":"all",
                    "name":"王翠花",
                    "age":18
                }
             */
            Map<String,Object> headers2=new HashMap<>();
            headers2.put("x-match","all");
            headers2.put("name","王翠花");
            headers2.put("age",18);
            channel.queueBind("queue2","header_ex","",headers2);
        }
    }
